# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=reportlab
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.5.42
pkgrel=1
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}=${pkgver}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgdesc="A proven industry-strength PDF generating solution (mingw-w64)"
arch=('any')
license=('custom')
url="https://bitbucket.org/rptlab/reportlab"
depends=("${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-python-pip"
         "${MINGW_PACKAGE_PREFIX}-python-pillow")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(https://files.pythonhosted.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz
        "0001-Do-not-specialcase-quote-LIBART_VERSION-on-Windows.patch")
sha256sums=('9c21f202697a6cea57b9d716288fc919d99cbabeb30222eebfc7ff77eac32744'
            '084b3574f7cb83dc7c9412b9976d672fda0f5f20cef6c6f6b66a6cefc31220ef')

prepare() {
  pushd ${_realname}-${pkgver}
    patch -p1 < ${srcdir}/0001-Do-not-specialcase-quote-LIBART_VERSION-on-Windows.patch
  popd

  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  export FT_LIB=${MINGW_PREFIX}/lib/libfreetype.a
  export FT_INC=${MINGW_PREFIX}/include/freetype2

  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  msg "Python test for ${CARCH}"
  # cd "${srcdir}/python-build-${CARCH}"
  # ${MINGW_PREFIX}/bin/python setup.py tests
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 src/reportlab/license.txt \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/python-${_realname}/LICENSE
}
